{extend name="layout/layout" /}
{block name="header"}{/block}

{block name="style"}
	<style>
		.bg-img{
			position: absolute;
			top: 0;
			left: 0;
			z-index: -1;
		}
		
		.sign-info{
			z-index: 1;
			background: rgba(0, 0, 0, 0);
			position: absolute;
			z-index: 99;
			padding-top: 50px;
			width: 100%;
		}
		
		.sign-info .point{
			width: 158px;
			height: 158px;
			margin: 0 auto;
			border: 8px solid #fff;
			background: #FFA800;
			display: flex;
			flex-direction: column;
			color: #fff;
			border-radius: 50%;
			justify-content: center;
			align-items: center;
			font-size: 19px;
		}
		
		.sign-info .point b{
			font-size: 40px;
			padding-top: 20px;
		}
		
		.sign-btn{
			background: #ff5500;
			color: #fff;
			height: 50px;
			line-height: 50px;
			border-radius: 25px;
			width: 90%;
			margin: 40px auto;
			text-align: center;
		}
		
		.sign-btn.no{
			background: #999;
		}
		
		.sign-record{
			margin-top: 80px;
			text-align: center;
			font-size: 14px;
			color: #999;
		}
		
		.sign-record b{
			font-size: 20px;
			color: #e60012;
			padding: 0 10px;
		}
	</style>
{/block}

{block name="main"}
	<div class="sign" v-cloak>
		<img src="/assets/img/sign_bg.png" alt="" class="bg-img img-responsive">
		<div class="sign-info">
			<div class="point">
				我的优惠券<br>
				<b>{{signData.point}}</b>
			</div>
			
			<div class="sign-record">已连续签到<b>{{signData.days}}</b>天</div>
			
			<div class="sign-btn" @tap="sign()" :class="signData.sign_status == 1 ? 'no': ''">{{signData.sign_status == 1 ? '已签到': '签到'}}</div>
		</div>
		
	</div>
{/block}
{block name="navbar"}{/block}
{block name="script"}
	<script>
		var myVue = new Vue({
			el:'.sign',
			data:{
                signData: {}
			},
			mounted: function(){
				if(token){
					this.token = token;
					console.log(this.token);
					this.checkSignStatus();
				} else {
					this.login();
				}

			},
			methods: {
				login:function(){
					location.href = '/mobile/user/login';
				},
				//检查签到状态及用户积分
				checkSignStatus: function() {
                    layer.open({
                        type: 2,
                        shadeClose: false,
                    });
                    var url =  'sign/signStatus';
                    var that = this;
                    request(that, {'url':url}, function(res){
                        if(res.code == 200) {
                            layer.closeAll();
                            that.signData = res.data;
                        } else {
                            mui.toast(res.msg);
                        }
                    });
				},
				//签到
                sign: function() {
				    if(this.signData.sign_status == 1) {
				        mui.toast('今天已签到');return;
				    }

                    layer.open({
                        type: 2,
                        shadeClose: false,
                    });
                    var url =  'sign/sign';
                    var that = this;
                    request(that, {'url':url}, function(res){
                        mui.toast(res.msg);
                        if(res.code == 200) {
                            that.signData.sign_status = 1;
                            that.signData.point = res.data.point;
                            that.signData.days = res.data.days;
                            layer.closeAll();
                        }
                    });
                }
			}
		});
	</script>
{/block}